<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/sweetalert.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/js/ions_alert.js}"></script>
    <script th:src="@{/js/sweetalert.min.js}"></script>
    <script type="text/javascript" th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">商品码</label>
            <div class="layui-input-inline" style="width: 200px;">
                <input type="text" lay-verify="title" placeholder="请输入商品码" autocomplete="off" class="layui-input"
                       id="wares_no" name="auth_no">
            </div>
            <div class="layui-form-mid layui-word-aux">商品标识码是商品唯一标志</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品名</label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" lay-verify="title" placeholder="请输入商品名称" autocomplete="off" class="layui-input"
                       id="wares_name" name="auth_name">
            </div>
            <div class="layui-form-mid layui-word-aux">请输入商品名称</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" id="wares_number" name="wares_number" lay-verify="title" placeholder="请输入商品数量"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">商品数量是整数</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">进价</label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" id="wares_trade" name="wares_trade" lay-verify="title" placeholder="请输入商品进价"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">进价要小于售价</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">售价</label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" id="wares_retail" name="wares_retail" lay-verify="title" placeholder="请输入商品零售价"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">售价要高于进价</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">积分值</label>
            <div class="layui-input-inline" style="width:200px;">
                <input type="text" id="wares_points" name="wares_points" lay-verify="title" placeholder="请输入商品积分值"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">不填写则是默认积分</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" id="testA">商品分类</label>
            <div class="layui-input-inline" style="width:200px;">
                <select name="interest" lay-filter="aihao" id="wares_category" autocomplete="off">
                    <dd  th:each="category:${CATEGORY_LIST}">
                        <option th:value="${category.getName()}" th:text="${category.getName()}"></option>
                    </dd>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">选择商品分类</div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">商品类型</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input name="is_active" id="is_active_1" type="radio" value="0" checked="checked" title="普通商品"/>-->
<!--                <input name="is_active" id="is_active_0" type="radio" value="1" title="特殊商品"/>-->

<!--                &lt;!&ndash;<input type="checkbox" id="is_active" name="is_active" lay-skin="switch" lay-text="启用|停用">&ndash;&gt;-->
<!--            </div>-->
<!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">商品单位</label>
            <div class="layui-input-inline" style="width: 200px;">
                <input class="layui-input" type="text" id="wares_class" autocomplete="off" name="wares_class" value="个"
                       placeholder="个">
            </div>
            <div class="layui-form-mid layui-word-aux">使用汉语量词规则</div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea id="wares_mark" name="wares_mark" placeholder="请输入商品备注" class="layui-textarea"></textarea>
            </div>
        </div>


        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-footer">
                    <button lay-filter="add" type="button" lay-submit class="layui-btn" id="wares_add_btn">立即提交</button>
                    <button onclick="x_admin_close()" class="layui-btn layui-btn-primary">返回</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script>

    // function selectGet(a){
    //     console.log("我真生气！");
    // }

    // $(function () {
    //     $("#category").change(function () {
    //         $.ajax({
    //             url: "AAAAAAAAAAAAAAAAA"
    //         });
    //         $("#testA").text("哦吼");
    //         console.log("行了吗？");
    //         // alert("哎呦你点我干啥？");
    //     });
    // });
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        // form.verify({
        //     nikename: function (value) {
        //         if (value.length < 5) {
        //             return '昵称至少得5个字符啊';
        //         }
        //     }
        //     , pass: [/(.+){6,12}$/, '密码必须6到12位']
        //     , repass: function (value) {
        //         if ($('#L_pass').val() != $('#L_repass').val()) {
        //             return '两次密码不一致';
        //         }
        //     }
        // 监听提交
        form.on('submit(add)', function (data) {
            // console.log(data);
            let wares_no = $("#wares_no").val();
            let wares_name = $("#wares_name").val();
            let wares_number = $("#wares_number").val();
            let wares_trade = $("#wares_trade").val();
            let wares_retail = $("#wares_retail").val();
            let wares_points = $("#wares_points").val();
            let wares_class = $("#wares_class").val();
            let wares_mark = $("#wares_mark").val();
            let wares_category = $("#wares_category").val();
            // 发异步，把数据提交给后台
            $.ajax({
                url: "addWares",
                type: "PUT",
                data:{
                    no: wares_no,
                    name: wares_name,
                    number: wares_number,
                    tradePrice: wares_trade,
                    retailPrice: wares_retail,
                    points: wares_points,
                    classifier: wares_class,
                    mark: wares_mark,
                    categoryName: wares_category
                },
                success: function (resultInfo) {
                    // console.log(resultInfo);
                    if(resultInfo.flag){
                        layer.alert(resultInfo.message, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else {
                        layer.alert(resultInfo.message, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                },error:function (e) {
                    // console.log("这里出现了问题！");
                    // console.log(e);
                }

            });
            return false;
        })

    });


    $(document).ready(function () {

        // $("#wares_add_btn").click(function () {
        //
        //     let wares_no = $("#wares_no").val();
        //     let wares_name = $("#wares_name").val();
        //     let wares_number = $("#wares_number").val();
        //     let wares_trade = $("#wares_trade").val();
        //     let wares_retail = $("#wares_retail").val();
        //     let wares_points = $("#wares_points").val();
        //     let wares_class = $("#wares_class").val();
        //     let wares_mark = $("#wares_mark").val();
        //     let wares_category = $("#wares_category").val();
        //
        //     $.ajax({
        //         url: "addWares",
        //         type: "PUT",
        //         data: {
        //             no:wares_no,
        //             name:wares_name,
        //             number:wares_number,
        //             tradePrice:wares_trade,
        //             retailPrice:wares_retail,
        //             points:wares_points,
        //             classifier:wares_class,
        //             mark:wares_mark,
        //             categoryName:wares_category
        //         },
        //         success:function (resultInfo) {
        //             if(resultInfo.flag){
        //                 alert(resultInfo.message);
        //                 window.close();
        //             }else {
        //                 alert(resultInfo.message);
        //             }
        //         },
        //         error:function (e) {
        //             console.log("出错了");
        //         }
        //     })
        // });

        // layui.use('form', function () {
        //     var form = layui.form;
        //
        //     // 监听提交
        //     form.on('submit(add)', function () {
        //         let wares_no = $("#wares_no").val();
        //         let wares_name = $("#wares_name").val();
        //         let wares_number = $("#wares_number").val();
        //         let wares_trade = $("#wares_trade").val();
        //         let wares_retail = $("#wares_retail").val();
        //         let wares_points = $("#wares_points").val();
        //         let wares_class = $("#wares_class").val();
        //         let wares_mark = $("#wares_mark").val();
        //         let wares_category = $("#wares_category").val();
        //         $.ajax({
        //             url: "addWares",
        //             type: "PUT",
        //             data: {
        //                 no: wares_no,
        //                 name: wares_name,
        //                 number: wares_number,
        //                 tradePrice: wares_trade,
        //                 retailPrice: wares_retail,
        //                 points: wares_points,
        //                 classifier: wares_class,
        //                 mark: wares_mark,
        //                 categoryName: wares_category
        //             },
        //             success:function (resultInfo) {
        //                 if(resultInfo.flag){
        //                     // alert(resultInfo.message);
        //                     layui.alert(resultInfo.message,{icon: 6});
        //
        //                     window.close();
        //                 }else {
        //                     // alert(resultInfo.message);
        //                     layui.alert(resultInfo.message,{icon: 2});
        //                 }
        //             },
        //             error: function (data) {
        //                 ions_alert.alertErrorToast(resultInfo.message)
        //                 setTimeout(x_admin_close, 1000)
        //             }
        //         })
        //     });
        //
        // });
    })

</script>
</body>

</html>